package com.qf.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.qf.domain.User;
import com.qf.service.UserService;

public class UserAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private UserService service;
    
	public UserService getService() {
		return service;
	}

	public void setService(UserService service) {
		this.service = service;
	}

	public String login(){
		System.out.println("login方法");
		List<User> list = service.login();
		for(User user:list){
			System.out.println(user.getName()+":"+user.getPassword());
		}
		return SUCCESS;
	}
	
	public String register(){
		String name=ServletActionContext.getRequest().getParameter("name");
	    String password=ServletActionContext.getRequest().getParameter("password");   
	    System.out.println(name+password);
	    User u=new User();
	    u.setName(name);
	    u.setPassword(password);
	    service.register(u);
	    
	    HttpServletRequest request=ServletActionContext.getRequest();
	    List<User> list=service.login();
	    request.getSession().setAttribute("list",list);
		return SUCCESS;
	}
    

}
